package com.qf.swagger1.domain;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@Data
@ApiModel("统一返回的结果实体")
public class R {

    @ApiModelProperty("结果码")
    private int code;

    @ApiModelProperty("成功或失败的描述信息")
    private String msg;

    @ApiModelProperty("成功的数据")
    private Object data;

    public static R success(Object data){
        R r = new R();
        r.setCode(Code.SUCCESS);
        r.setData(data);
        return r;
    }

    public static R error(String msg,int code){
        R r = new R();
        r.setCode(code);
        r.setMsg(msg);
        return r;
    }

    public static R error(String msg){
        R r = new R();
        r.setCode(Code.ERROR);
        r.setMsg(msg);
        return r;
    }
}
